

//检测名称v与某表t中的所有数据中是否在某列c上有重名，返回1表示冲突，返回 0表示不冲突
function CheckNameConflict(t, c, v) {
    var err = "";

    $.ajax({
        type: "GET",
        url: "../handle/checkNameConflict.ashx",
        data: { tname: t, cname: c, value: v },
        dataType: "html",
        async: false,
        success: function (data) {
            err = data;
        }
    });
    return err;
}

//产生select标签
function selectOption(r, i, v,d,c) {
    var sel = "";
    $.ajax({
        type: "POST",
        url: "../handle/selectOption.ashx",//获取时间段下拉列表框
        data: {
            name:r,
            id: i,
            value: v,
            disname:d,
            condition:c
        },
        dataType: "html",
        async: false,
        success: function (data) {
            sel = data;
        }
    });
    return sel;
}

//验证日期yyyy-MM-dd是否合法
function CheckDateFormat(date) {

    var result = date.match(/((^((1[8-9]\d{2})|([2-9]\d{3}))(-)(10|12|0?[13578])(-)(3[01]|[12][0-9]|0?[1-9])$)|(^((1[8-9]\d{2})|([2-9]\d{3}))(-)(11|0?[469])(-)(30|[12][0-9]|0?[1-9])$)|(^((1[8-9]\d{2})|([2-9]\d{3}))(-)(0?2)(-)(2[0-8]|1[0-9]|0?[1-9])$)|(^([2468][048]00)(-)(0?2)(-)(29)$)|(^([3579][26]00)(-)(0?2)(-)(29)$)|(^([1][89][0][48])(-)(0?2)(-)(29)$)|(^([2-9][0-9][0][48])(-)(0?2)(-)(29)$)|(^([1][89][2468][048])(-)(0?2)(-)(29)$)|(^([2-9][0-9][2468][048])(-)(0?2)(-)(29)$)|(^([1][89][13579][26])(-)(0?2)(-)(29)$)|(^([2-9][0-9][13579][26])(-)(0?2)(-)(29)$))/);
    if (result == null)
        return false;
    else return true;


}
//检验某个日期是date否是星期week
function CheckWeek(date, week) {
    var mdate = new Date(Date.parse(date.replace(/-/g, "/")));
    var weekDay = mdate.getDay();
    if (weekDay != week) {
        return false;
    }
    return true;
}




//日期相加减函数
function DateOperator(date, days, operator) {

    date = date.replace(/-/g, "/"); //更改日期格式
    var nd = new Date(date);
    nd = nd.valueOf();
    if (operator == "+") {
        nd = nd + days * 24 * 60 * 60 * 1000;
    } else if (operator == "-") {
        nd = nd - days * 24 * 60 * 60 * 1000;
    } else {
        return false;
    }
    nd = new Date(nd);
    var y = nd.getFullYear();
    var m = nd.getMonth() + 1;
    var d = nd.getDate();
    if (m <= 9) m = "0" + m;
    if (d <= 9) d = "0" + d;
    var cdate = y + "-" + m + "-" + d;
    return cdate;
}


//验证正整数
function CheckNumPositive(val) {

    var result = val.match("^[0-9]*[1-9][0-9]*$");
    if (result == null)
        return false;
    else return true;


}
//删除选择数据前的询问
function IsSelCbx() {
    var selArray = document.getElementsByName("ids");
    for (i = 0; i < selArray.length; i++) {
        if (selArray[i].checked) {
            if (confirm("确定要删除所选数据？"))
                return true;
            else {
                return false;
            }
        }
    }
    alert("未选择任何数据项！");
    return false;
}
//编辑数据时只能保证选择一项
function IsSelCbxMore() {
    var selArray = document.getElementsByName("ids");
    var j = 0;
    for (i = 0; i < selArray.length; i++) {
        if (selArray[i].checked) j++;
    }
    if (j > 1) { alert("请勿选择多项数据"); return false; }
    if (j == 0) { alert("未选择任何数据项！"); return false; }
    return true;

}


function IsSelCbxNoAlert() {
    var selArray = document.getElementsByName("ids");

    for (i = 0; i < selArray.length; i++) {
        if (selArray[i].checked) {
            return true;
        }
    }
    alert("未选择任何数据项！");
    return false;
}

function SelAllCbx() {
    var selArray = document.getElementsByName("ids");
    var selAllCbx = document.getElementById("cbxSelAll");
    for (i = 0; i < selArray.length; i++) {
        selArray[i].checked = true;
    }

}

function SelAllNoCbx() {
    var selArray = document.getElementsByName("ids");
    var selAllCbx = document.getElementById("cbxUnSelAll");
    for (i = 0; i < selArray.length; i++) {
        selArray[i].checked = false;
    }

}

function GoUrl(url) {
    window.location.href = url;
}


//获取url参数
function QueryString(name) {
    var value="", i,nam;
    var str = location.href;
    var num = str.indexOf("?")
    str = str.substr(num + 1);
    var arrtmp = str.split("&");
    for (i = 0; i < arrtmp.length; i++) {
        num = arrtmp[i].indexOf("=");
        if (num > 0) {
            nam = arrtmp[i].substring(0, num);
            value = arrtmp[i].substr(num + 1);
            if (name == nam) return value;
        }
    }
    return value;
}
